# to cross build, export CROSS_COMPILE=arm-linux-
CC ?= $(CROSS_COMPILE)gcc
CFLAGS += -O2 -Wall -Iinclude `pkg-config --cflags opencv`
LDFLAGS += -L./lib ${LINK_LIBS} -lpthread `pkg-config --libs opencv`

# local static library
LIB_GPIOX = lib/libgpiox.a
LIB_US100 = lib/libus100.a
LIB_WFLYCTRL = lib/libwflyctrl.a
#LIB_PLANENAVIGATION = lib/libPlaneNavigation.a
LIB_CAMERALOCATE = lib/libC_CamDet.a
LIBS = ${LIB_GPIOX} ${LIB_US100} ${LIB_WFLYCTRL} ${LIB_PLANENAVIGATION}
LINK_LIBS = -lgpiox -lus100 -lwflyctrl -lC_CamDet #-lPlaneNavigation

DEPEND_DIRS = ./gpiox ./us100 ./wflyctrl ./CameraLocate #./PlaneNavigation

OBJS = start.o mainctrl.o monitor.o

default: ${DEPEND_DIRS} start

start: $(OBJS)
	g++ ${CFLAGS} -o $@ $^ ${LDFLAGS}

# libs and objs
$.o:
.PHONY: ${DEPEND_DIRS} ${CLEAN_DIRS}

${DEPEND_DIRS}:
	${MAKE} -C $@

# cleanup
clean:
	${RM} start
distclean: clean
	${RM} start.o ${OBJS}
	@for dir in ${DEPEND_DIRS} ; do \
		${MAKE} -C $${dir} distclean; \
		if [ `echo $$?` -ne 0 ] ; then \
			exit 1; \
		fi; \
	done
